#include "example.srpc.h"
#include "workflow/WFFacilities.h"

using namespace srpc;


static void echo_callback(EchoResponse *response, srpc::RPCContext *context)
{
    // 判断远程过程调用是否成功
    if (context->success()) {
        std::cout << "Response: { message=" << response->message() << " }\n";
    } else {
        std::cout << "status code: " << context->get_status_code()
            << ", error: " << context->get_error()
            << ", errmsg: " << context->get_errmsg() << "\n";
    }
}

int main()
{
	const char *ip = "127.0.0.1";
	unsigned short port = 9527;
    // 创建SRPC的客户端
	Example::SRPCClient client{ ip, port };

    // 创建SRPCClientTask
    SRPCClientTask* echoTask = client.create_Echo_task(echo_callback);

    // 设置请求
	EchoRequest req;
    req.set_message("Hello, SRPC!\n");
    req.set_name("xixi");
    echoTask->serialize_input(&req);

    WFFacilities::WaitGroup waitGroup { 1 };
    SeriesWork* series = Workflow::create_series_work(echoTask, [&waitGroup](const SeriesWork*)
    {
        waitGroup.done();    
    });

    series->start();

    waitGroup.wait();
	return 0;
}
